package com.njtoyo.taxi.admin.converter;

import org.bson.Document;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;

@ReadingConverter
public class GeoJsonPointReadConverter implements Converter<Document, GeoJsonPoint> {

    @Override
    public GeoJsonPoint convert(Document source) {
        double[] coordinates = (double[]) source.get("coordinates");
        return new GeoJsonPoint(coordinates[0], coordinates[1]);
    }
}